home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / misc_pto / mwpetz03 / sysmets2.c < prev    next >
C/C++ Source or Header  |  1991-06-02  |  5KB  |  154 lines

  1. /* SYSMETS2.C -- System Metrics Display Program No. 2 */
  2.  
  3. #ifdef MEWEL
  4. #include <window.h>
  5. #undef NULL
  6. #define NULL 0
  7. #else
  8. #include <windows.h>
  9. #endif
  10. #include <stdio.h>
  11. #include "sysmets.h"
  12.  
  13. long FAR PASCAL WndProc (HWND, unsigned, WORD, LONG) ;
  14.  
  15. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  16.      HANDLE   hInstance, hPrevInstance ;
  17.      LPSTR    lpszCmdLine ;
  18.      int      nCmdShow ;
  19.      {
  20.      static   char szAppName [] = "SysMets2" ;
  21.      HWND     hWnd ;
  22.      MSG      msg ;
  23.      WNDCLASS wndclass ;
  24.  
  25.      if (!hPrevInstance) 
  26.           {
  27.           wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  28.           wndclass.lpfnWndProc   = WndProc ;
  29.           wndclass.cbClsExtra    = 0 ;
  30.           wndclass.cbWndExtra    = 0 ;
  31.           wndclass.hInstance     = hInstance ;
  32.           wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  33.           wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  34.           wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
  35.           wndclass.lpszMenuName  = NULL ;
  36.           wndclass.lpszClassName = szAppName ;
  37.  
  38.           if (!RegisterClass (&wndclass))
  39.                return FALSE ;
  40.           }
  41.  
  42.      hWnd = CreateWindow (szAppName, "Get System Metrics",
  43.                          WS_OVERLAPPEDWINDOW | WS_VSCROLL,
  44.                          CW_USEDEFAULT, 0,
  45.                          CW_USEDEFAULT, 0,
  46.                          NULL, NULL, hInstance, NULL) ;
  47.  
  48.      ShowWindow (hWnd, nCmdShow) ;
  49.      UpdateWindow (hWnd) ;
  50.  
  51.      while (GetMessage (&msg, NULL, 0, 0))
  52.           {
  53.           TranslateMessage (&msg) ;
  54.           DispatchMessage (&msg) ;
  55.           }
  56.      return msg.wParam ;
  57.      }
  58.  
  59. long FAR PASCAL WndProc (hWnd, iMessage, wParam, lParam)
  60.      HWND         hWnd ;
  61.      unsigned     iMessage ;
  62.      WORD         wParam ;
  63.      LONG         lParam ;
  64.      {
  65.      static short xChar, yChar, xClient, yClient, nVscrollPos ;
  66.      char         szBuffer [80] ;
  67.      HDC          hDC ;
  68.      int          i ;
  69.      TEXTMETRIC   tm ;
  70.      PAINTSTRUCT  ps ;
  71.  
  72.      switch (iMessage)
  73.           {
  74.           case WM_CREATE:
  75.                hDC = GetDC (hWnd) ;
  76.                GetTextMetrics (hDC, &tm) ;
  77.                xChar = tm.tmAveCharWidth ;
  78.                yChar = tm.tmHeight + tm.tmExternalLeading ;
  79.                ReleaseDC (hWnd, hDC) ;
  80.  
  81.                SetScrollRange (hWnd, SB_VERT, 0, NUMLINES, FALSE) ;
  82.                SetScrollPos   (hWnd, SB_VERT, nVscrollPos, TRUE) ;
  83.                break ;
  84.  
  85.           case WM_SIZE:
  86.                yClient = HIWORD (lParam) ;
  87.                xClient = LOWORD (lParam) ;
  88.                break ;
  89.  
  90.           case WM_VSCROLL:
  91.                switch (wParam)
  92.                     {
  93.                     case SB_LINEUP:
  94.                          nVscrollPos -= 1 ;
  95.                          break ;
  96.  
  97.                     case SB_LINEDOWN:
  98.                          nVscrollPos += 1 ;
  99.                          break ;
  100.  
  101.                     case SB_PAGEUP:
  102.                          nVscrollPos -= yClient / yChar ;
  103.                          break ;
  104.  
  105.                     case SB_PAGEDOWN:
  106.                          nVscrollPos += yClient / yChar ;
  107.                          break ;
  108.  
  109.                     case SB_THUMBPOSITION:
  110.                          nVscrollPos = LOWORD (lParam) ;
  111.                          break ;
  112.  
  113.                     default:
  114.                          break ;
  115.                     }
  116.                nVscrollPos = max (0, min (nVscrollPos, NUMLINES)) ;
  117.  
  118.                if (nVscrollPos != GetScrollPos (hWnd, SB_VERT))
  119.                     {
  120.                     SetScrollPos (hWnd, SB_VERT, nVscrollPos, TRUE) ;
  121.                     InvalidateRect (hWnd, NULL, TRUE) ;
  122.                     }
  123.                break ;
  124.  
  125.           case WM_PAINT:
  126.                BeginPaint (hWnd, &ps) ;
  127.  
  128.                for (i = 0 ; i < NUMLINES ; i++)
  129.                  if (1 - nVscrollPos + i >= 0)
  130.                     TextOut (ps.hdc, xChar, yChar * (1 - nVscrollPos + i),
  131.                               szBuffer, 
  132.                          sprintf (szBuffer, "%-20s%-35s%5d",
  133.                               sysmetrics[i].szLabel,
  134.                               sysmetrics[i].szDesc,
  135.                               GetSystemMetrics (sysmetrics[i].nIndex))) ;
  136.  
  137.                EndPaint (hWnd, &ps) ;
  138.                break ;
  139.  
  140.           case WM_DESTROY:
  141.                PostQuitMessage (0) ;
  142.                break ;
  143.  
  144.           default:
  145.                return DefWindowProc (hWnd, iMessage, wParam, lParam) ;
  146.           }
  147.      return 0L ;
  148.      }
  149.  
  150. #ifdef MEWEL
  151. MEWELmain(0)
  152. #endif
  153.  
  154.